﻿using System;
using ServiceStack.Redis;
using Funq;
using System.Collections.Generic;

namespace PuSuoPai
{
	public class RedisMgr
	{
		static public readonly RedisMgr Instance = new RedisMgr ();

		PooledRedisClientManager mRedisPool;

		RedisClient mRedis;

		public RedisMgr ()
		{
			RedisClientManagerConfig redisConfig = new RedisClientManagerConfig ();
			redisConfig.AutoStart = true;
			redisConfig.DefaultDb = 0;
			redisConfig.MaxReadPoolSize = 60;
			redisConfig.MaxWritePoolSize = 60;

			mRedisPool = new PooledRedisClientManager (0, "127.0.0.1:3679");
			mRedisPool.ConnectTimeout = 5;
			mRedisPool.PoolTimeout = 3;
			mRedisPool.IdleTimeOutSecs = 30;

			mRedis = new RedisClient ("127.0.0.1", 3679);
		}

		public IRedisClient GetClient()
		{
			return mRedis;
			//return mRedisPool.GetClient ();
		}

		public string MakeHashId(string className, string objectID)
		{
			return "urn:" + className + ":" + objectID;
		}
	}
}

